{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "05a35247",
   "metadata": {},
   "source": [
    "**2022/10/10 week07**"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5300e8a6",
   "metadata": {},
   "source": [
    "# 本周学习知识点\n",
    "> **1.有序的数据结构---字符串(str)**\n",
    ">\n",
    "> **2.有序的数据结构---列表（list）**"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7d9b92a6",
   "metadata": {},
   "source": [
    "# 1.字符串 （string)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "93b97e41",
   "metadata": {},
   "source": [
    "> 1.字符串的基本内容 \n",
    ">\n",
    "> 2.字符串的方法及函数"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ea7be538",
   "metadata": {},
   "source": [
    "## 1.1[关于字符串的基本内容](https://docs.python.org/3/tutorial/introduction.html#strings)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f6a3edf8",
   "metadata": {},
   "source": [
    " * Single quotes: 'allows embedded \"double\" quotes'\n",
    "\n",
    " * Double quotes: \"allows embedded 'single' quotes\"\n",
    "\n",
    " * Triple quoted: '''Three single quotes''', \"\"\"Three double quotes\"\"\"\n",
    "\n",
    "注： \n",
    "**单引号和双引号导致的结果无差异，**主要是为了防止内容里有引号，python无法识别\n",
    "\n",
    "**三引号‘‘‘’’’和 “““”””常用于保留完整的文本信息，也就意味着python可以存放任何语言的代码信息**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "cae78f6b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'spam eggs'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'spam eggs'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "a11aeabd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'str'>\n"
     ]
    }
   ],
   "source": [
    "print(type('spam eggs' ))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "3ee35004",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'str'>\n"
     ]
    }
   ],
   "source": [
    "print(type(\"spam eggs\" ))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "2c55f484",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (3578565646.py, line 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  Input \u001b[1;32mIn [5]\u001b[1;36m\u001b[0m\n\u001b[1;33m    'doesn't'\u001b[0m\n\u001b[1;37m           ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "'doesn't'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "58b9ae15",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"dones't\""
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 以上解决方案\n",
    "\"dones't\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "f7ea90f7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"doesn't\""
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 反义字符的使用\n",
    "'doesn\\'t'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "421dca49",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"'dones't\""
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"'dones't\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "d47b6bc6",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 三引号：保留字符串信息的 格式信息,保留完整的数据信息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "ac816fa0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"doesn't\""
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''doesn't'''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "24f5fee6",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (2102282546.py, line 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  Input \u001b[1;32mIn [16]\u001b[1;36m\u001b[0m\n\u001b[1;33m    ''Triple quoted strings may span multiple lines - all associated whitespace will be included in the string literal.\u001b[0m\n\u001b[1;37m      ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "''Triple quoted strings may span multiple lines - all associated whitespace will be included in the string literal.\n",
    "\n",
    "String literals that are part of a single expression and have only whitespace between them will be implicitly converted to a single string literal. That is''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "8e1e7bff",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Triple quoted strings may span multiple lines - all associated whitespace will be included in the string literal.\n",
      "\n",
      "String literals that are part of a single expression and have only whitespace between them will be implicitly converted to a single string literal. That is\n"
     ]
    }
   ],
   "source": [
    "print('''Triple quoted strings may span multiple lines - all associated whitespace will be included in the string literal.\n",
    "\n",
    "String literals that are part of a single expression and have only whitespace between them will be implicitly converted to a single string literal. That is''')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "f49c0c97",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Usage: thingy [OPTIONS]\n",
      "     -h                        Display this usage message\n",
      "     -H hostname               Hostname to connect to\n",
      "\n"
     ]
    }
   ],
   "source": [
    "print(\"\"\"\\\n",
    "Usage: thingy [OPTIONS]\n",
    "     -h                        Display this usage message\n",
    "     -H hostname               Hostname to connect to\n",
    "\"\"\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "d61bc90a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<script type=\"importmap\" nonce=\"\"> { \"imports\": {\"rms-answers-HomepageVNext-PeregrineWidgets\":\"https://assets.msn.com/bundles/v1/bingHomepage/latest/widget-initializer.js\"} } </script>\n"
     ]
    }
   ],
   "source": [
    "print('''<script type=\"importmap\" nonce=\"\"> { \"imports\": {\"rms-answers-HomepageVNext-PeregrineWidgets\":\"https://assets.msn.com/bundles/v1/bingHomepage/latest/widget-initializer.js\"} } </script>''')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5835eb56",
   "metadata": {},
   "source": [
    "## 1.2 [关于字符串的方法及函数](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5982fd39",
   "metadata": {},
   "source": [
    "> 1.字符串是**可以拼接的**（字符串的运算）,用 + 进行字符串之间的拼接\n",
    ">\n",
    "> 2.字符串是**有顺序的**,从第一个字符开始，从0依次往后；有长度，可以用**len()**检查字符串的长度\n",
    ">\n",
    "> 3.字符串的取值：\n",
    ">>\n",
    ">> 1.取单个值 :从左往右（正数，第一个值是0），从右往左（负数，第一个值是-1）\n",
    ">> \n",
    ">> 2.取多个值 :切片的方法，两个值作为 取值的区间\n",
    ">\n",
    "> 字符串的方法及函数\n",
    "> \n",
    ">> 1.in 查询成员是否存在\n",
    ">>\n",
    ">> 2.str.count() 查询数量\n",
    ">>\n",
    ">> 3.str.isdigit() 判断字符串是否是 数字"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "8c291d7c",
   "metadata": {},
   "outputs": [],
   "source": [
    "new_name = [\"小明\",\"小红\",\"张杰\",\"李华\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "cde08434",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "广州南方学院欢迎小明\n",
      "广州南方学院欢迎小红\n",
      "广州南方学院欢迎张杰\n",
      "广州南方学院欢迎李华\n"
     ]
    }
   ],
   "source": [
    "for i in new_name:\n",
    "    print(\"广州南方学院欢迎\"+ i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "dbd7703a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院欢迎小明'"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"广州南方学院欢迎\"+\"小明\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "d13f14b0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院欢迎小明'"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text = \"广州南方学院欢迎小明\"\n",
    "text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "017b4301",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'院'"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "10303c8b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广'"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "124f830b",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (1795767343.py, line 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  Input \u001b[1;32mIn [28]\u001b[1;36m\u001b[0m\n\u001b[1;33m    text{8}\u001b[0m\n\u001b[1;37m        ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "text{8}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "4ef54680",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "cb615bf7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'学院'"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[4]+text[5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "c8a5e358",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'院'"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "fc84e153",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'方学'"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 使用 切片 的方法进行多个值取值\n",
    "text[3:5]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "16565156",
   "metadata": {},
   "source": [
    "* in 查询成员"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "32520917",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"广州\"in text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "3f70cf4a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"北京\"in text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "29fbda7b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text.count('广州')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ee2d6043",
   "metadata": {},
   "source": [
    "* str.count() 查询数量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "efebe47b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "19\n",
      "19\n"
     ]
    }
   ],
   "source": [
    "print(19)\n",
    "print(\"19\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "7c5a9488",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "19 <class 'int'>\n",
      "19 <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "age_li = 19\n",
    "age_le = \"19\"\n",
    "print(age_li,type(age_li))\n",
    "print(age_le,type(age_le))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "f719a34e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "age_le.isdigit()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "32c95b7c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text.isdigit()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d4c76bb7",
   "metadata": {},
   "source": [
    "# 2. 有序的数据结构——列表(list)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bcc48811",
   "metadata": {},
   "source": [
    "* Python knows a number of compound data types, used to group together other values. The most versatile is the list, which can be written as a list of comma-separated values (items) between square brackets. Lists might contain items of different types, but usually the items all have the same type."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1c493b92",
   "metadata": {},
   "source": [
    "> 1.列表的基本运算法则（参考：有序的数据结构的运算法则列表）\n",
    ">\n",
    "> 2.列表的一般方法（要求：全部掌握，并且做总结在课后笔记中）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "778566fe",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 思考：假设，有这样一个场景，我要录入/存放一个班的同学的信息（名单信息），用字符串存放是否可行？如何取值呢？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "5678cc7f",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 字符串存放\n",
    "网二_name = \"李华，小明，李晓华，小红\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "cada7307",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "12"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(网二_name)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "ce99af4d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'李华'"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 字符串取值,比较麻烦\n",
    "网二_name[0:2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "5f325a25",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'小明'"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网二_name[3:5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "c81dc820",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'李晓华'"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网二_name[6:9]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2101e4b0",
   "metadata": {},
   "source": [
    "* 对比字符串和列表\n",
    "> 1.字符串是按照字符进行数据取值\n",
    ">\n",
    "> 2.列表是按照元素进行数据取值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "52289580",
   "metadata": {},
   "outputs": [],
   "source": [
    "网三_name_list = [\"小明\",\"小红\",\"莉莉\",\"李华\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "95436d38",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(网三_name_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "ecf51e92",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'小明'"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_name_list[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "2270962a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['李华']"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_name_list[-1:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "964f8b40",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['莉莉', '李华']"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_name_list[-2:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "019fe8b5",
   "metadata": {},
   "outputs": [],
   "source": [
    "网三_age_list = [14,15,18,19]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "249a3195",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "14"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_age_list[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "2334b09e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[14, 15, 18, 19]"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_age_list[:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "da9007b3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_age_list.count(19)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ce2476fe",
   "metadata": {},
   "source": [
    "# 2.2[列表的方法](https://docs.python.org/3/library/stdtypes.html#lists)\n",
    "> 1.增加\n",
    ">\n",
    "> 2.删除\n",
    ">\n",
    "> 3.修改\n",
    ">\n",
    "> 4.查询in,count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "96f9b942",
   "metadata": {},
   "outputs": [],
   "source": [
    "names = [\"Mike\",\"Marry\",\"Jan\",\"Jack\"]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8c32bc2f",
   "metadata": {},
   "source": [
    "* 学习方法\n",
    "> 1.listname.Tab键 查看所有方法名称\n",
    ">\n",
    "> 2.help(listname.function) 查看其中一个方法的具体操作内容"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fd40d577",
   "metadata": {},
   "source": [
    "> 课后练习（做一个表格，总结列表的方法）："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "id": "787e98fa",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Collecting prettytable\n",
      "  Downloading prettytable-3.4.1-py3-none-any.whl (26 kB)\n",
      "Requirement already satisfied: wcwidth in d:\\anaconda3\\lib\\site-packages (from prettytable) (0.2.5)\n",
      "Installing collected packages: prettytable\n",
      "Successfully installed prettytable-3.4.1\n",
      "Note: you may need to restart the kernel to use updated packages.\n"
     ]
    }
   ],
   "source": [
    "pip install prettytable"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "id": "473a7dfb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "+-----------+-------------+---------+\n",
      "|  列表方法 | Description | example |\n",
      "+-----------+-------------+---------+\n",
      "|  append() |       增加元素，增加在列表的末尾\t       |     1\tnames.append(\"zhichao\")， ['Mike', 'Marry', 'Jan', 'Jack', 'zhichao']     |\n",
      "| Paragraph |     Text    |    0    |\n",
      "+-----------+-------------+---------+\n"
     ]
    }
   ],
   "source": [
    "from prettytable import PrettyTable\n",
    "\n",
    "\n",
    "table = PrettyTable(['列表方法', 'Description', 'example'])\n",
    "table.add_row(['append()', '增加元素，增加在列表的末尾\t', '''1\tnames.append(\"zhichao\")， ['Mike', 'Marry', 'Jan', 'Jack', 'zhichao']'''])\n",
    "table.add_row(['Paragraph', 'Text', '0'])\n",
    "print(table)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "id": "fc570756",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function append:\n",
      "\n",
      "append(object, /) method of builtins.list instance\n",
      "    Append object to the end of the list.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.append)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "5cbf594a",
   "metadata": {},
   "outputs": [],
   "source": [
    "names.append(\"liye\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "efa546a5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mike', 'Marry', 'Jan', 'Jack', 'liye']"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "4d9b2464",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function insert:\n",
      "\n",
      "insert(index, object, /) method of builtins.list instance\n",
      "    Insert object before index.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.insert)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "59081b20",
   "metadata": {},
   "outputs": [],
   "source": [
    "names.insert(1,\"Alex\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "2f841133",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mike', 'Alex', 'Marry', 'Jan', 'Jack', 'liye']"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
